Skip to content

bpo-38191: Accept arbitrary keyword names in NamedTuple() and TypedDict().#16222

Merged
serhiy-storchaka merged 3 commits into
python:masterfrom
serhiy-storchaka:typingnamedtuple-new
Sep 17, 2019
Merged

bpo-38191: Accept arbitrary keyword names in NamedTuple() and TypedDict().#16222
serhiy-storchaka merged 3 commits into
python:masterfrom
serhiy-storchaka:typingnamedtuple-new

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Sep 17, 2019

Copy link
Copy Markdown
Member

This includes such names as "cls", "self", "typename", "_typename",
"fields" and "_fields".
Passing positional arguments by keyword is deprecated.

https://bugs.python.org/issue38191

…ct().

This includes such names as "cls", "self", "typename", "_typename",
"fields" and "_fields".
Passing positional arguments by keyword is deprecated.
Comment thread Lib/typing.py Outdated

@pablogsal pablogsal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks, Serhiy for working on this!

If I understand correctly, the next step is to use PEP570 notation on master, right?

@serhiy-storchaka

Copy link
Copy Markdown
Member Author

Yes, and drop this ugly boilerplate code.

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What deprecation schedule do you propose? Can we start using '/' in 3.9? In 3.8?

@ilevkivskyi Maybe this version should be upstreamed (downstreamed?) to github.com/python/typing?

@@ -0,0 +1,4 @@
Constructors of :class:`~typing.NamedTuple` and :class:`~typing.TypedDict`
types accept now arbitrary keyword argument names, including "cls", "self",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"now accept"

@serhiy-storchaka

Copy link
Copy Markdown
Member Author

3.7 -- no deprecation (but arbitrary keywords supported)
3.8 -- deprecation
3.9 -- use '/'

I think a chance to break somebody's code is small, so we can use a short deprecation period. But there is still a risk, and we do not want to break working code at this stage of 3.8.

@serhiy-storchaka
serhiy-storchaka merged commit 2bf31cc into python:master Sep 17, 2019
@serhiy-storchaka
serhiy-storchaka deleted the typingnamedtuple-new branch September 17, 2019 18:22
@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7, 3.8.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 17, 2019
…ct(). (pythonGH-16222)

This includes such names as "cls", "self", "typename", "_typename",
"fields" and "_fields".
Passing positional arguments by keyword is deprecated.
(cherry picked from commit 2bf31cc)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-bot

Copy link
Copy Markdown

GH-16237 is a backport of this pull request to the 3.8 branch.

@miss-islington

Copy link
Copy Markdown
Contributor

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.7 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 2bf31ccab3d17f3f35b42dca97f99576dfe2fc7d 3.7

serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Sep 17, 2019
…ypedDict(). (pythonGH-16222)

This includes such names as "cls", "self", "typename", "_typename",
"fields" and "_fields".
Passing positional arguments by keyword is deprecated..
(cherry picked from commit 2bf31cc)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington added a commit that referenced this pull request Sep 17, 2019
…ct(). (GH-16222)

This includes such names as "cls", "self", "typename", "_typename",
"fields" and "_fields".
Passing positional arguments by keyword is deprecated.
(cherry picked from commit 2bf31cc)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-bot

Copy link
Copy Markdown

GH-16239 is a backport of this pull request to the 3.7 branch.

serhiy-storchaka added a commit that referenced this pull request Sep 17, 2019
…16222) (GH-16239)

This includes such names as "cls", "self", "typename" and "fields".
(cherry picked from commit 2bf31cc)
@ilevkivskyi

Copy link
Copy Markdown
Member

Maybe this version should be upstreamed (downstreamed?) to github.com/python/typing?

Yes, I think so. Also probably the signatures in typeshed should be updated.

@gvanrossum

Copy link
Copy Markdown
Member

Also probably the signatures in typeshed should be updated.

I'm not sure -- are those signatures even used, given the special-casing of TypedDict and NamedTuple?

@ilevkivskyi

Copy link
Copy Markdown
Member

I'm not sure -- are those signatures even used, given the special-casing of TypedDict and NamedTuple?

Mypy only uses signature of NamedTuple, but other tools may use them in a different manner, see also python/typeshed#3235

ilevkivskyi added a commit to python/typing that referenced this pull request Nov 24, 2019
Fixes #677

This backports python/cpython#16222 (Python 3 only). The Python 2 backport is more tricky so I skip it for now.
@serhiy-storchaka serhiy-storchaka removed their assignment Dec 29, 2020
JelleZijlstra pushed a commit to python/typing_extensions that referenced this pull request May 19, 2022
Fixes python/typing#677

This backports python/cpython#16222 (Python 3 only). The Python 2 backport is more tricky so I skip it for now.
JelleZijlstra pushed a commit to python/typing_extensions that referenced this pull request May 19, 2022
Fixes python/typing#677

This backports python/cpython#16222 (Python 3 only). The Python 2 backport is more tricky so I skip it for now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants